package com.lovo.service.impl;

import com.lovo.dao.UserDAO;
import com.lovo.model.DTO.UserDTO;
import com.lovo.model.UserDO;
import com.lovo.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private UserDAO userDAO;

    @Override
    public void save(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        userDO.setName(userDTO.getName());
        userDO.setPwd(userDTO.getPwd());
        userDAO.save(userDO);
    }


    @Override
    public UserDTO findByNameAndPwd(String name, String pwd) {
        UserDO userDO = userDAO.findByNameAndPwd(name, pwd);
        if (userDO == null) {
            return null;
        } else {
            UserDTO userDTO = new UserDTO();
            userDTO.setUserId(userDO.getUserId());
            userDTO.setName(name);
            userDTO.setPwd(pwd);
            return userDTO;
        }
    }


}
